package com.sunfeng.jksj.p24;

import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
 * @Author : 孙峰
 * @Description: CompletionStage
 * @Date : 2022/3/2  8:46
 */
public class Demo02 {
    public static void main(String[] args) {
        /**
         * 说明thenApply   Function  应用    R apply(T t);
         */
        CompletableFuture<String> stringCompletableFuture = CompletableFuture
                .supplyAsync(() -> new Student("Sun Feng", 18, "男"))
                .thenApply(student -> student.getName() + " is good man !!")
                .thenApply(String::toUpperCase);

        System.out.println(stringCompletableFuture.join());

      
        /**
         *  说明thenAccept   消费一个     void accept(T t);
         */
        CompletableFuture
                .supplyAsync(() -> new Student("Sun Feng", 18, "男"))
                .thenAccept(student -> System.out.println(student.getName()));


        /**
         * 执行完了
         */
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture
                .supplyAsync(() -> new Student("Sun Feng", 18, "男"))
                .thenRun(() -> {
                    System.out.println("执行好了");
                });


        /**
         * CompletionStage thenCompose(fn);
         */


    }
}
